package com.blb.auth_service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.blb.auth_service.mapper.UserMapper;
import com.blb.auth_service.service.IUserService;
import com.blb.common.entity.UserInfo;
import com.blb.common.utils.Md5Utils;
import org.springframework.stereotype.Service;

@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, UserInfo> implements IUserService {

    @Override
    public UserInfo login(String username, String password) {
        UserInfo user = this.getOne(new QueryWrapper<UserInfo>().lambda().eq(UserInfo::getUsername, username));
        if(user == null){
            return null;
        }
        String encrypt = Md5Utils.encrypt(password, user.getSalt());
        if(encrypt.equals(user.getPassword())){
            return user;
        }
        return null;
    }
}
